package com.taobao.txc.resourcemanager;

import com.taobao.txc.common.LoggerInit;
import com.taobao.txc.common.LoggerWrap;
import com.taobao.txc.common.TxcContext;
import com.taobao.txc.common.b.c;
import com.taobao.txc.common.c.B;
import com.taobao.txc.common.c.v;
import com.taobao.txc.common.c.w;
import com.taobao.txc.common.c.x;
import com.taobao.txc.common.j;
import com.taobao.txc.common.util.d;
import com.taobao.txc.resourcemanager.mt.MtResourceManager;
import java.io.File;
import java.util.HashMap;
import org.apache.commons.lang.StringUtils;

public abstract class i
  implements b
{
  private static final LoggerWrap a = LoggerInit.logger;
  private static HashMap<String, b> b = new HashMap();
  private com.taobao.txc.a.a.b c;
  private int d = 3;
  
  protected static b a(String paramString)
  {
    if (paramString == null) {
      throw new c("null ResourceManager class name");
    }
    if (b.get(paramString) == null) {
      synchronized (i.class)
      {
        if (b.get(paramString) == null) {
          try
          {
            Object localObject1;
            if (paramString.compareTo("rt") == 0) {
              localObject1 = new com.taobao.txc.resourcemanager.d.a();
            } else if (paramString.compareTo("mt") == 0) {
              localObject1 = new MtResourceManager();
            } else if (paramString.compareTo("at") == 0) {
              localObject1 = new k();
            } else {
              localObject1 = new k();
            }
            b.put(paramString, localObject1);
            a.info(String.format("TxcBaseResourceManagerImpl %s inited.", new Object[] { paramString }));
          }
          catch (Exception localException)
          {
            throw new c("Error happened:" + paramString);
          }
        }
      }
    }
    return (b)b.get(paramString);
  }
  
  public int a()
  {
    return this.d;
  }
  
  public com.taobao.txc.a.a.b b()
  {
    return this.c;
  }
  
  public void a(com.taobao.txc.a.a.b paramb)
  {
    this.c = paramb;
  }
  
  private long a(v paramv)
  {
    if (TxcContext.inTxcTransaction())
    {
      paramv.a(j.a(TxcContext.getCurrentXid()));
      try
      {
        w localw = (w)b().a(paramv, 30000L);
        if (a.c()) {
          a.debug(paramv.toString());
        }
        if (localw.a() != B.a.a()) {
          throw new c(localw.a(), localw.b());
        }
        long l = localw.d();
        return l;
      }
      catch (Throwable localThrowable)
      {
        localThrowable = localThrowable;
        a.error("", "invoke msg failed. " + paramv);
        throw new c(localThrowable);
      }
      finally {}
    }
    throw new IllegalStateException("current thread is not bind to txc transaction.");
  }
  
  public long a(String paramString1, String paramString2, com.taobao.txc.common.a parama)
  {
    v localv = new v();
    localv.a(paramString1);
    localv.b(paramString2);
    localv.a((byte)parama.a());
    com.taobao.txc.resourcemanager.c.a.a().a(localv);
    try
    {
      return a(localv);
    }
    catch (Throwable localThrowable)
    {
      com.taobao.txc.resourcemanager.c.a.a().a(localv, localThrowable);
    }
    return 0L;
  }
  
  public void a(long paramLong, boolean paramBoolean, String paramString1, String paramString2)
  {
    int i = a();
    for (int j = 1;; j++) {
      try
      {
        a(paramLong, paramBoolean, paramString1, paramString2, j);
      }
      catch (c localc)
      {
        if (j <= i)
        {
          a.a("", "reportStatus branch:" + paramLong + ", retry:" + j, localc);
        }
        else
        {
          a.a("", "reportStatus failed. branch:" + paramLong, localc);
          throw localc;
        }
      }
    }
  }
  
  private void a(long paramLong, boolean paramBoolean, String paramString1, String paramString2, int paramInt)
  {
    if (TxcContext.inTxcTransaction())
    {
      x localx = new x();
      localx.b(paramLong);
      localx.a(paramBoolean);
      localx.b(paramString1);
      localx.a(j.a(TxcContext.getCurrentXid()));
      localx.a(paramString2);
      try
      {
        if (a.c()) {
          a.debug(localx.toString());
        }
        b().a(localx, -1L);
      }
      catch (Throwable localThrowable)
      {
        throw new c(localThrowable);
      }
    }
    else
    {
      throw new IllegalStateException("current thread is not bind to txc transaction.");
    }
  }
  
  protected void a(Integer paramInteger)
  {
    int i = 7;
    if (paramInteger != null)
    {
      if (paramInteger.intValue() <= 0) {
        return;
      }
      i = paramInteger.intValue();
    }
    String str1 = System.getProperty("user.home");
    if (StringUtils.isEmpty(str1)) {
      str1 = "/home/admin";
    }
    String str2 = str1 + "/logs/txc";
    File localFile = new File(str2);
    if (!localFile.exists())
    {
      a.info("clean log failed. no dir " + str2);
      return;
    }
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("find ").append(str2).append(" -mtime +").append(i);
    localStringBuilder.append(" -name 'txc*.log.*' -type f -delete");
    localStringBuilder.append(";");
    localStringBuilder.append("find ").append(str2).append(" -mtime +").append(i);
    localStringBuilder.append(" -name 'txc.*.log*' -type f | while read origfile; do fname=$(basename $origfile); pid=$(echo $fname | cut -d'.' -f2); if [ $(ps -ef|grep java|grep $pid|wc -l) -eq 0 ]; then rm -f $origfile; fi; done");
    com.taobao.txc.common.util.a locala = new com.taobao.txc.common.util.a();
    try
    {
      locala.a(new String[] { "/bin/sh", "-c", localStringBuilder.toString() }, null);
      String str3 = locala.a(d.b, 10000L);
      a.info(String.format("clean log done. cmd:[%s] res:[%s]", new Object[] { localStringBuilder.toString(), str3 }));
    }
    catch (Exception localException)
    {
      a.warn("clean log failed. " + localException.getMessage());
    }
    finally
    {
      locala.a();
    }
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.resourcemanager.i
 * JD-Core Version:    0.7.0.1
 */